package net.oschina.zbus;

import org.zbus.client.Broker;
import org.zbus.client.broker.SingleBroker;
import org.zbus.client.broker.SingleBrokerConfig;
import org.zbus.client.service.ServiceConfig;
import org.zbus.client.service.ServiceHandler;
import org.zbus.client.service.ServiceLoader;
import org.zbus.client.service.ServiceProvider;
import org.zbus.common.logging.Logger;
import org.zbus.common.logging.LoggerFactory;
import org.zbus.remoting.Message;

public class SimpleServiceExample implements ServiceProvider, ServiceHandler {
	private static final Logger log = LoggerFactory.getLogger(SimpleServiceExample.class);
	
	@Override
	public ServiceConfig getConfig() { 
		ServiceConfig config = new ServiceConfig();
		config.setMq("SimpleExample"); 
		config.setServiceHandler(this); //ServiceHandler必须
		return config;
	}
	
	@Override
	public Message handleRequest(Message msg) {
		log.info(msg.toString());
		
		return null;
	}

	public static void main(String[] args) throws Exception {
		SingleBrokerConfig config = new SingleBrokerConfig();
		config.setBrokerAddress("127.0.0.1:15555");
		Broker broker = new SingleBroker(config);
		final ServiceLoader serviceLoader = new ServiceLoader(broker);
		
		
		ServiceProvider sp = new SimpleServiceExample(); 
		serviceLoader.loadService(sp);
	}

}
